home *** CD-ROM | disk | FTP | other *** search
/ Archive Magazine CD 1995 / Archive Magazine CD 1995.iso / discs / prog_disc / volume_1 / issue_11 / renum / input next >
Encoding:
Text File  |  1995-06-13  |  11.6 KB  |  290 lines

  1.  
  2.  
  3.             GENERAL INPUT ROUTINE
  4.  
  5. The Archimedes provides an excellent interface between an application
  6. program and the user: the WIMP manager. This should be used wherever
  7. possible by such applications software. It does, however, have one
  8. drawback. Many programs require the input of data; the processing of
  9. data is, after all, what computers do best. It will therefore be
  10. necessary for the user to type in such data. What is needed, is a way of
  11. managing and controlling that exchange, validating entries and
  12. monitoring all input.
  13.  
  14. Included here is a set of such routines. They provide a whole host
  15. of facilities, all of which may be selected by the programmer. Wherever
  16. possible, they also possess room for expansion, allowing additions to be
  17. made. For each routine I have included a worded description of the
  18. functions provided, followed by a technical discussion of the procedures
  19. and functions used.
  20.  
  21. There are also a number of service routines, which I have added since
  22. they may be of some use in other applications software.
  23.  
  24.     Input Routine
  25.  
  26.     Call Syntax:    PROCIN(HORIZ%, VERT%, LGTH%, TYPE%)
  27.  
  28.             HORIZ%    Horizontal position of input on screen
  29.             VERT%    Vertical position of input
  30.             LGTH%    Length of input
  31.             TYPE%    Type of input required
  32.  
  33. This routine is designed to eliminate typing errors. When called, the
  34. routine places on the screen a set of inwardly facing arrows, >  <. The
  35. location of these brackets, and the seperation between them, are
  36. determined by the input parameters to the routine. The entry asked for
  37. by the program is then made within the brackets. It is not possible to
  38. move the cursor away from that area, provided the cursor editing keys
  39. have been disabled with *FX4,1. Once the size and position of the input
  40. required is determined, the only other requirement of the routine is the
  41. type of data it is to accept.
  42.  
  43. Using TYPE%, it is possible to select one of four basic input types,
  44. plus any number of other optional routines. At present, however, only
  45. five additional functions are provided by the system, although extending
  46. this is very straightforward.
  47.  
  48. TYPE% is entered as, in effect, the decimal form of a binary number.
  49. Basically, the number contained in TYPE% is converted from decimal to
  50. binary, and then the procedures act on the condition of individual bit
  51. settings as described below.
  52.  
  53.     Bits 0 and 1.
  54.  
  55. These are combined to provide a number ranging from 0 to 3, in effect
  56. they identify which of the four basic input types have been selected.
  57. They may be described as follows.
  58.  
  59.             0    General Alphanumeric Input
  60.             1    Alphabetic keys only
  61.             2    Numeric keys only
  62.             3    Return only
  63.  
  64. If, for example, option 1 is selected, only alphabetic keys may be used.
  65. The routine will accept a-z, A-Z and the space bar. Any other key
  66. pressed will be ignored by the routine. The numeric setting will only
  67. allow numeric digits, a point, '.', and a minus sign. It also permits
  68. the use of 'Z', which has a special meaning as described later.
  69.  
  70. The remaining bits of the number, when set, call into operation
  71. procedures which have the following effects.
  72.  
  73.    Bit        Decimal Value    Use                Flag Set
  74.     2             4        Restricts input to return only   FLAG(1)
  75.     3                8          Prints BACK$ instead of spaces   FLAG(2)
  76.                                 If this is used, and BACK$ has 
  77.                                 been set, BACK$ is printed between
  78.                          the brackets instead of spaces.
  79.     4               16          Checks number validity if set    FLAG(3)
  80.                              This only allows one '-' and 
  81.                           one '.' per entry.
  82.     5            32        Test to see if entry purely
  83.                  numeric.             FLAG(4)
  84.     6            64          Treats type-in as a password     FLAG(5)
  85.  
  86.  
  87. The output from the routine comes in various forms. 
  88.  
  89.     AN$        Holds the output as a string
  90.     AN        Holds the value of AN$ if the base type was numeric
  91.     FLAG(0)        Set if the entry was 'Z'
  92.  
  93. This last flag setting is used to determine if the user wishes to escape
  94. from the function and return to a previous level or menu. Anyone
  95. familiar with other versions of Basic may recall CTRL-Z, which halts
  96. execution in a similay way.
  97.  
  98. So, to accept a 12 character password at position TAB(20,10) on the
  99. screen, the following should be issued:
  100.  
  101.     PROCIN(20,10,12,64)
  102.  
  103. €PE
  104.     Technical Explanation:
  105.  
  106. PROCIN consists mainly of three REPEAT...UNTIL loops. On entry,
  107. PROCLIMITS is called. This routine takes the value submitted in TYPE%
  108. and translates it into the various condition flags. On exit from LIMITS,
  109. the flags in the array FLAG(10) have been set as indicated above, with
  110. TYPE% containing a number in the range 0 to 3, which is the base input
  111. type.
  112.  
  113. PROCSPACE then displays the input brackets (filled with BACK$ if FLAG(2)
  114. has been set. The routine then enters into its main loop, scanning the
  115. keyboard for depressed keys. The ASCII value of any key pressed is helf
  116. in CHAR. CHAR is then tested by FNVALID_CHAR to ensure that it is valid
  117. according to the strictures of the base input type (held in TYPE%).  If
  118. it is invalid, it is simply ignored. If the character is valid, it is
  119. added to AN$. It is also displayed on the screen. This is achieved by
  120. PROCSHOW_CHAR, which will display a # symbol if a password input has
  121. been requested.
  122.  
  123. If the character entered is delete, the last character of AN$ is removed
  124. and the cursor is backspaced. If the input has already reached the
  125. maximum length, a beep is issued and the character ignored. (These two
  126. functions handled by DELCHECK and SIZECHECK respectively).
  127.  
  128. The program loops until RETURN is pressed.
  129.  
  130. At this point the entry is complete. The routine now has the opportunity
  131. of testing the entry according to the wishes of the programmer. 
  132.  
  133. PROCDECIMAL scans the entered string, searching for the minus sign or
  134. decimal point, '-' & '.'. If more than one of each is detected, an error
  135. message is displayed (via PROCERROR), and a flag is set to indicate
  136. this. Provided the type-in is correct the flag is left clear and control
  137. passes on.
  138.  
  139. PROCNUMERIC_CHECK tests the entry to see if it is purely numeric in
  140. nature. (It is assumed that a base input type has been used). This
  141. routine can then inform the program that in fact the entry was purely
  142. numeric.
  143.  
  144.         Single Character Input Routine
  145.  
  146.         Call Syntax:    PROCIN2(HORIZ%,VERT%,VALID$)
  147.  
  148.         HORIZ%    Horizontal position of input
  149.         VERT%    Vertical position of input
  150.         VALID$    Valid Characters
  151.  
  152. This routine may be used to accept a single keystroke from the keyboard.
  153. To differentiate this from the main input routine, the brackets used are
  154. curved, ie ( ). On entry to the routine, HORIZ% AND VERT% contain the
  155. coordinates of the input, while VALID$ is a string composed of all the
  156. legally acceptable keys for the routine to test.
  157.  
  158. On exit from the routine, AN$ contains the key actually pressed, and AN
  159. the position of that character within VALID$.
  160.  
  161. As with PROCIN, FLAG(0) will be set to 1 if the string entered is 'Z'.
  162.  
  163.     Compaction Routine
  164.  
  165.     Call Sytax:    PROCCOMPACT(NUM%,SIZE%)
  166.  
  167.             NUM%    Number to be packed
  168.             SIZE%    Size of destination string in bytes
  169.  
  170. This routine accepts a signed numeric integer and transforms it to a
  171. binary packed string. This is useful if the number is to be stored as
  172. part of a data record for which the standard file format is
  173. unwieldy.Since the routine also stores the sign of the number, it is
  174. vital that the value of SIZE be large enough to take into account the
  175. sign. For example, the largest number that can be held in 1 byte is
  176. +127, the smallest -127.
  177.  
  178. The packed string is returned as BIN$.
  179.  
  180.     Expansion Routine
  181.  
  182.     Call Syntax:    PROCEXPAND(BINS$,SIZE%)
  183.  
  184.         BIN$    Compressed Number
  185.         SIZE%   Size of number
  186.  
  187. This routine reverses the action of PROCCOMPACT, by returning an integer
  188. from a compacted string. 
  189.  
  190.     Error Routine
  191.  
  192.     Call Synatx:    PROCERROR(Error%)
  193.  
  194.         Error%    The required error number
  195.  
  196. This routine will display an error message in the event of a program
  197. trapping an error of some kind. The Error messages themselves are
  198. predefined and held in an array Error$, which is declared and filled by
  199. the routine PROCINIT_SYS. INIT_SYS is one once, on first entry into any
  200. program using these routines. Basically, the procedure uses a case
  201. statement to determine a suitable screen location for the error message.
  202. I have selected a line one up from the bottom of the screen, and roughly
  203. central. It would be quit straightforward (using DIV), to ensure that
  204. the text was centred exactly, in which case the HLOC% field would not be
  205. required as a start point, but could be modified to hold the width of
  206. the screen in characters.
  207.  
  208. The routine displays the message at the calculated point, emits a Bell
  209. character (VDU 7), pauses for 0.75 seconds, then clears away the message
  210. and exits. It is a very simple case to extend the dimension of Error$
  211. and add as many error messages as are required by an application
  212. program. It would, however, required some modification in order to
  213. operate correctly within a Window from the WIMP environment.
  214.  
  215.  
  216.     Delay Routine
  217.  
  218.     Call Syntax:    PROCDELAY(DELAY%)
  219.  
  220.         DELAY%    Required pause in 100ths of a second.
  221.  
  222.     This routine halts the program for the specified length of time.
  223.  
  224.     Format Routine
  225.  
  226.     Call Syntax:    PROCFORMAT(AMOUNT$,LGTH%)
  227.  
  228.                        AMOUNT$    String to be reformatted
  229.                        LGTH%    Required length of output string
  230.  
  231.  
  232. This routine will accept a string input and a specified length. It will
  233. then evaluate the string as a numerical expression of currency. The
  234. object of the procedure is to return to the program a new string, which
  235. contains the amount received in a formatted state. For example,
  236.  
  237.     the string ".1" with a length specified of 5, would return,
  238.  
  239.            " 0.10" to the program.
  240.  
  241. The procedure can handle negative numbers as well as positive, although
  242. care should be taken to ensure that space for a minus sign is included
  243. in the length of the return string specified.
  244.  
  245.  
  246.     Restore Routine
  247.  
  248.     Call Syntax:    PROCRESTORE(LABEL$)
  249.  
  250.         LABEL$    Label of DATA block to be located
  251.  
  252. This routine will restore the BASIC data pointer to a given block of
  253. data in the program, provided that the block is prefixed with a label
  254. string. This label is then passed to PROCRESTORE as the only input
  255. parameter. The routine then scans down through all available DATA
  256. statements until the desired one is reached. Note: if no match is found
  257. the program will abort with an 'Out of Data' error. Note also (I cobbled
  258. this routine from Risc User, but it is so useful I thought I would
  259. include it anyway).
  260.  
  261.     Initialise Routine
  262.  
  263.     Call Syntax:    PROCINIT_SYS
  264.  
  265. This routine is used to declare all of the system variables used by the
  266. above procedures and functions. The large block of numbers represent the
  267. ascii codes for the various base input types. Space has been left to add
  268. additional error messages. There is also room to add declarations of
  269. other arrays should this be necessary, although it would be far more
  270. sensible to define another array called INIT_PROG, which could then be
  271. used to declare any other variables used by the program. i.e., reserve
  272. INIT_SYS for system variables only.
  273.  
  274. So there we are. The procedures listed are by no means complete. They
  275. all work in the manner explained (at least, I haven't found any bugs
  276. yet!), and provide a useful service in a program. They are all capable
  277. of extension, and, I have no doubt, improvement. If anyone out there
  278. spots a potential bug, or has a suggestion for the improvement of any of
  279. the above listed routines, please encourage them to write in and air
  280. their views. 
  281.  
  282. I am revising and working on these on a daily basis, and will endeavour
  283. to keep you informed of any more which I develop in the future.
  284.  
  285. One thing that I would be interested to know concerns the line numbering
  286. which I have employed, with each procedure starting at a 100 boundry. In
  287. my opinion this makes locating such a procedure or function fairly
  288. straightforward and, I believe, neatens the look of the proram. Any
  289. comments?
  290.